﻿<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="util.JdbcUtil" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="bean.WarehouseBean" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
  <head>
    <title>warehouse</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
    <link href="data/styles.css" type="text/css" rel="stylesheet"/>
    <link href="files/warehouse/styles.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="layui/css/laytable.css">
    <script src="resources/scripts/jquery-3.2.1.min.js"></script>
    <script src="resources/scripts/axure/axQuery.js"></script>
    <script src="resources/scripts/axure/globals.js"></script>
    <script src="resources/scripts/axutils.js"></script>
    <script src="resources/scripts/axure/annotation.js"></script>
    <script src="resources/scripts/axure/axQuery.std.js"></script>
    <script src="resources/scripts/axure/doc.js"></script>
    <script src="resources/scripts/messagecenter.js"></script>
    <script src="resources/scripts/axure/events.js"></script>
    <script src="resources/scripts/axure/recording.js"></script>
    <script src="resources/scripts/axure/action.js"></script>
    <script src="resources/scripts/axure/expr.js"></script>
    <script src="resources/scripts/axure/geometry.js"></script>
    <script src="resources/scripts/axure/flyout.js"></script>
    <script src="resources/scripts/axure/model.js"></script>
    <script src="resources/scripts/axure/repeater.js"></script>
    <script src="resources/scripts/axure/sto.js"></script>
    <script src="resources/scripts/axure/utils.temp.js"></script>
    <script src="resources/scripts/axure/variables.js"></script>
    <script src="resources/scripts/axure/drag.js"></script>
    <script src="resources/scripts/axure/move.js"></script>
    <script src="resources/scripts/axure/visibility.js"></script>
    <script src="resources/scripts/axure/style.js"></script>
    <script src="resources/scripts/axure/adaptive.js"></script>
    <script src="resources/scripts/axure/tree.js"></script>
    <script src="resources/scripts/axure/init.temp.js"></script>
    <script src="resources/scripts/axure/legacy.js"></script>
    <script src="resources/scripts/axure/viewer.js"></script>
    <script src="resources/scripts/axure/math.js"></script>
    <script src="resources/scripts/axure/jquery.nicescroll.min.js"></script>
    <script src="data/document.js"></script>
    <script src="files/warehouse/data.js"></script>
    <script type="text/javascript">
      $axure.utils.getTransparentGifPath = function() { return 'resources/images/transparent.gif'; };
      $axure.utils.getOtherPath = function() { return 'resources/Other.html'; };
      $axure.utils.getReloadPath = function() { return 'resources/reload.html'; };
    </script>
    <script src="${pageContext.request.contextPath }/js/jquery.js"></script>
    <script >
      function add(wid){
        location.href="warehouseadd.jsp";
      }

      function modify(wid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="warehousemodify?wid="+wid;
        }
      }
      function del(wid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="warehousedelete?wid="+wid;
        }
      }

    </script>
    <style>
      .dadbox{
        position: relative;
      }
      .addbtn{
        position: absolute;
        top: 80px;
        left: 50px;
      }
      .table_huowu{
        position: absolute;
        top: 120px;
        left: 50px;
      }
      .table_huowu table{
        border-collapse:collapse;
        width: 800px;
      }
      #u185_div{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        padding-top: 40px;
      }
      #wid,#wname{
        width:200px;
        height: 30px;
      }
      #sub{
        width: 70px;
        height: 30px;
        background-color:rgba(0, 121, 254, 0.5);
        border-radius:3px;
        border-width:0px;
        font-family:'微软雅黑', sans-serif;
        font-weight:400;
        font-style:normal;
        font-size:14px;
        color:#FFFFFF;
        line-height:20px;
      }
      #sut{
        background-color:rgb(130,212,248) ;
        width: 80px;
        height: 30px;
        text-align: center;
        color: #ffffff;
        border: 0 solid #ffffff;
        border-radius:3px;
      }
      td{
        white-space: nowrap;
      }
    </style>
    <%
      String sql ="SELECT * FROM warehouse";
      try {
        PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
        ResultSet set = ps.executeQuery();

        ArrayList<WarehouseBean> arr = new ArrayList<WarehouseBean>();
        while (set.next()){
          WarehouseBean wa = new WarehouseBean();
          wa.setWid(set.getInt(1));
          wa.setWname(set.getString(2));
          wa.setWperson(set.getString(3));
          wa.setAddrss(set.getString(4));
          wa.setStatics(set.getString(5));
          arr.add(wa);
        }
        session.setAttribute("arr", arr);

      } catch (Exception e) {
        e.printStackTrace();
      }
    %>
  </head>
  <body>
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u184" class="ax_default box_1">
        <div id="u184_div" class="dadbox">
          <div class="addbtn">
            <input type="submit" value="添加" id="sut" onclick="add(${wa.wid})" />
          </div>
          <div class="table_huowu">
            <table class="layui-table">
              <thead>
              <tr>
                <th>仓库id</th>
                <th>仓库名称</th>
                <th>仓库管理员</th>
                <th>仓库地址</th>
                <th>状态</th>
                <th>操作</th>
              </tr>
              </thead>
             <tbody id="tbody">
             <c:forEach items="${arr}" var="wa">
               <tr>
                 <td>${wa.wid}</td>
                 <td>${wa.wname}</td>
                 <td>${wa.wperson}</td>
                 <td>${wa.addrss}</td>
                 <td>${wa.statics}</td>
                 <td>
                   <input type="button" value="删除" onclick="del(${wa.wid})" />
                   <input type="button" value="修改" onclick="modify(${wa.wid })" />
                 </td>
               </tr>
             </c:forEach>
             </tbody>
            </table>
          </div>
        </div>
        <div id="u184_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u185" class="ax_default box_1">
        <div id="u185_div" class="">
          <input id="wid" placeholder="仓库ID" type="text"/>
          <input type="text" id="wname" placeholder="仓库名称"/>
          <input type="submit"id="sub" value="筛选" onclick="hunt()">
        </div>
        <div id="u185_text" class="text " style="display:none; visibility: hidden">
          <p></p >
        </div>
      </div>


      <!-- Unnamed (矩形) -->
      <div id="u190" class="ax_default box_1">
        <div id="u190_div" class=""></div>
        <div id="u190_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图片 ) -->
      <div id="u191" class="ax_default _图片_">
        <img id="u191_img" class="img " src="images/customer/u149.png"/>
        <div id="u191_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u192" class="ax_default label">
        <div id="u192_div" class=""></div>
        <div id="u192_text" class="text ">
          <p><span>筛选</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u193" class="ax_default box_1">
        <div id="u193_div" class=""></div>
        <div id="u193_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u194" class="ax_default _图片_">
        <img id="u194_img" class="img " src="images/customer/u152.svg"/>
        <div id="u194_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u195" class="ax_default label">
        <div id="u195_div" class=""></div>
        <div id="u195_text" class="text ">
          <p><span>列表</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u196" class="ax_default label">
        <div id="u196_div" class=""></div>
        <div id="u196_text" class="text ">
          <p><span>仓库信息管理</span></p>
        </div>
      </div>

      <!-- Unnamed (组合) -->
      <div id="u197" class="ax_default" data-left="72" data-top="307" data-width="349" data-height="34">
      </div>
    </div>
    <script src="resources/scripts/axure/ios.js"></script>
    <script>
      function hunt(){
        var wid = $("#wid").val();
        var wname = $("#wname").val();
        if (wid==null &&wname==null){
          location.href="warehouse.jsp";
        }
        $.ajax({
          url : "warehousehunt?wid="+wid+"&wname="+wname,//提交地址
          type : "post",//提交方式（get,post）
          dataType : "json",//指定服务器返回的数据类型
          success : function(data) {//请求成功后的回调函数
            console.log(data);
            $("#tbody").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
            var trStr = "";
            for (var i = 0; i < data.length; i++) {
              trStr += "<tr><td>" + data[i].wid +
                      "</td><td>" + data[i].wname +
                      "</td><td>" + data[i].wperson +
                      "</td><td>" + data[i].addrss +
                      "</td><td>" + data[i].statics +
                      "</td><td>" + " <input type='button' value='删除' onclick='del(${wa.wid})' />"
                      +"<input type='button' value='修改' onclick='modify(${wa.wid})' />"+
                      "</td></tr>"
            }
            $("#tbody").show().append(trStr);//向<tbody>内部追加内容
          },
          error : function() {
            alert('请求失败');
          }
        });
      }

    </script>
  </body>
</html>
